import { prisma } from '@/lib/prisma'
import { NextResponse } from 'next/server'

export async function PUT(request: Request, { params }: { params: { id: string } }) {
  const { name } = await request.json()
  const role = await prisma.role.update({
    where: { id: Number(params.id) },
    data: { name },
  })
  return NextResponse.json(role)
}

export async function DELETE({ params }: { params: { id: string } }) {
  try {
    await prisma.role.delete({
      where: { id: Number(params.id) },
    })
    return NextResponse.json({ message: '角色已删除' })
  } catch (error) {
    console.error('删除角色失败:', error)
    return NextResponse.json({ error: '删除角色失败' }, { status: 500 })
  }
}